/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.action;

import static com.lineage.server.model.skill.L1SkillId.EFFECT_POTION_OF_BATTLE;
import static com.lineage.server.model.skill.L1SkillId.EXP_BONUS_OF_POTION;

import org.w3c.dom.Element;

import com.lineage.server.PacketCreate;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.L1Item;

/**
 * Class <code>L1ItemAddExpAction</code> .
 * 
 * @author jrwz
 * @version 2012-7-22下午02:05:57
 * @see com.lineage.server.model.item.action
 * @since JDK1.7
 */
public final class L1ItemAddExpAction extends L1ItemXmlAction {

    /** 经验倍率. */
    private final double expBonus;
    /** 类型. */
    private final String type;

    /**
     * 道具动作:技能动画特效.
     * 
     * @param element
     *            - XML 文档中的一个元素
     */
    public L1ItemAddExpAction(final Element element) {
        super(element);
        this.expBonus = L1ItemXmlParser.getDoubleAttribute(element, "倍率", 0.0);
        this.type = L1ItemXmlParser.getStringAttribute(element, "类型", "");
    }

    @Override
    public L1Item execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        pc.delRepeatSkillEffect(EXP_BONUS_OF_POTION);
        pc.delRepeatSkillEffect(EFFECT_POTION_OF_BATTLE);
        pc.setExpBonusOfPotion(this.expBonus);
        if (this.type.equalsIgnoreCase("神力药水")) {
            final int time = 900 * 1000;
            pc.setSkillEffect(EXP_BONUS_OF_POTION, time);
            PacketCreate.get().sendSinglePackets(pc, "由于狩猎获得的经验值量增加了");
        } else if (this.type.equalsIgnoreCase("战斗药水")) {
            final int time = 3600 * 1000;
            pc.setSkillEffect(EFFECT_POTION_OF_BATTLE, time);
        }
        return null;
    }
}
